/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package skv.db.daten.entities;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import skv.db.iface.DbHandler;
import skv.db.abst.SkvEntity;

/**
 * Stellt die Benutzerrollen Tabelle dar.
 * @author Alex
 */
public class Rolle extends SkvEntity{
    private String rollenName;

    public Rolle(int id, DbHandler dbh) {
        
        this.id = id;
        this.dbh = dbh;
        getMyData();
    }

    public Rolle(String rollenName, DbHandler dbh) {
        
        this.rollenName = rollenName;
        this.dbh = dbh;
        create();
    }

    

   
    public String getRollenName() {
        return rollenName;
    }

    public void setRollenName(String rollenName) {
        this.rollenName = rollenName;
    }

    @Override
    public void update() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void getMyData() {
        ResultSet rs = dbh.doQuery("SELECT * FROM rollen WHERE rollenID = " + id);
        try {
            rs.next();
            this.rollenName = rs.getString("rollenName");
            rs.close();
        } catch (SQLException ex) {
            Logger.getLogger(Rolle.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    @Override
    public void create() {
        dbh.doQuery("INSERT INTO `skv`.`rollen` (`rollenID`, `rollenName`) "
                + "VALUES (NULL, '"+this.getRollenName()+"');");  
        this.getLastInsertID();
       
    }

    @Override
    public boolean isUnique() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void delete() {
        ResultSet rs = dbh.doQuery("DELETE FROM `skv`.`rollen` WHERE `skv`.`rollen`.`rollenID`="+this.id);
        
    }
    
    
}
